<template>
  <div>
    <div class="lk-primary" @click="save" >
      <i class="fa mr5" :class="hasPraise?'fa-thumbs-up':'fa-thumbs-o-up'" title="赞"></i>
      <span v-if="count>0">{{ count }}个</span>赞
    </div>
  </div>
</template>

<script>
export default {
  props: {
    objType: {
      type: String,
      default: 'default'
    },
    objKey: {
      type: String,
      default: '0'
    }
  },
  data () {
    return {
      hasPraise: false,
      count: 0
    }
  },
  mounted () {
    this.search()
  },
  watch: {
    objType () {
      this.search()
    },
    objKey () {
      this.search()
    }
  },
  methods: {
    search () {
      this.$http.get('/zg-system/praise/count', {
        objType: this.objType,
        objKey: this.objKey
      }, data => {
        this.count = parseInt(data)
      })
      this.$http.get('/zg-system/praise/search', {
        objType: this.objType,
        objKey: this.objKey
      }, data => {
        this.hasPraise = data
      })
    },
    save () {
      this.needLogin(() => {
        this.$http.post('/zg-system/praise/save', {
          objType: this.objType,
          objKey: this.objKey
        }, data => {
          this.count = data.count
          this.hasPraise = data.hasPraise
        })
      })
    }
  }
}
</script>
<style lang="less" scoped>
</style>
